'''
author:        Wang Chenyang <cy-wang21@mails.tsinghua.edu.cn>
date:          2024-09-24
Copyright © Department of Physics, Tsinghua University. All rights reserved
'''

from wordcloud import WordCloud
import matplotlib.pyplot as plt
from collections import Counter
import re

# 示例文本
text = "Python is a high-level, interpreted, general-purpose programming language. " \
       "Python is often described as an easy to learn, powerful programming language."

# 使用正则表达式去除标点符号，并分词
words = re.findall(r'\w+', text.lower())

# 计算词频
word_counts = Counter(words)

# 使用词频生成词云
wordcloud = WordCloud(width=800, height=400, background_color="white").generate_from_frequencies(word_counts)

# 显示词云图片
plt.figure(figsize=(10, 5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()
